package com.ztk.threadbasic.wait;

public class Wait01 {

    public static void main(String[] args) {
        Wait01 wait01 = new Wait01();

        Thread thread = new Thread(() -> {
            synchronized (wait01) {
                while (true) {
                    System.out.println("开始休眠");
                    try {
                        wait01.wait();
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("结束休眠");
                    break;
                }
            }
        });

        thread.start();

        Thread thread1 = new Thread(() -> {
            synchronized (wait01) {
                synchronized (wait01) {
                    System.out.println("开始唤醒");
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    wait01.notify();
                    System.out.println("唤醒结束");
                }
            }
        });
        thread1.start();
    }
}
